package com.zoe.onelink.actuate.check;

import com.zoe.onelink.plugin.check.AbstractEnvironmentChecker;
import com.zoe.onelink.plugin.check.model.PropertyCheckResult;
import org.springframework.core.env.Profiles;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-09-27
 */
public class NacosEnvironmentChecker extends AbstractEnvironmentChecker {

    @Override
    protected List<PropertyCheckResult<?>> doCheck() {
        String ephemeralKey = "spring.cloud.nacos.discovery.ephemeral";
        Boolean isEphemeral = this.getProperty(ephemeralKey, Boolean.class, true);
        boolean isProd = this.getEnvironment().acceptsProfiles(Profiles.of("prod"));
        List<PropertyCheckResult<?>> propertyCheckResults = new ArrayList<>();
        // 正式环境且开启永久实例
        if (isProd && !isEphemeral) {
            PropertyCheckResult<Boolean> checkResult = new PropertyCheckResult<Boolean>()
                    .setPropKey(ephemeralKey)
                    .setPropValue(false)
                    .setLevel(PropertyCheckResult.Level.SEVERITY)
                    .setMessage("请勿在正式环境中开启Nacos永久实例");
            propertyCheckResults.add(checkResult);
        }
        return propertyCheckResults;
    }

}
